// const base_url = 'https://shb.hnymxk.top/sys'
// const domain_name = 'https://shbcdn.hnymxk.top/'

const base_url = 'https://shb.sdtxcq.com/sys'
const domain_name = 'https://7ncdn.sdtxcq.com/'

const timeout = 7000
export default (params) => {
	let url = params.url;
	let method = params.method || "get";
	let data = params.data || {};
	let header = {
		'X-Requested-With': 'XMLHttpRequest',
		'Content-Type': 'application/json',
		...params.header
	};
	const token = uni.getStorageSync('token');
	if (token) {
		header.SysToken = token;
	}
	return new Promise((resolve, reject) => {
		uni.request({
			url: base_url + url,
			method: method,
			header: header,
			data: data,
			timeout,
			success(res) {
				if ([0, 10, 20, 30, 18, 28].includes(res.data.code)) {
					resolve(res.data);
				} else {
					switch (res.data.code) {
						case -11:
							uni.removeStorageSync("userInfo");
							uni.removeStorageSync("token");
							uni.removeStorageSync("address");
							uni.showModal({
								title: "提示",
								content: "当前未登录，请重新登录后重试",
								showCancel: true,
								success(res) {
									uni.reLaunch({
										url: '/pages/login/login'
									})
								},
							});
							reject(res.data);
							break;
						default:
							reject(res.data);
							break;
					}
				}
			},
			fail(err) {
				if (err.errMsg == "request:fail") {
					uni.showModal({
						title: '提示',
						content: '网络异常，请检查网络连接',
						success(res) {
							if (res.confirm) {
								setTimeout(() => {
									uni.reLaunch({
										url: '/pages/index/index'
									})
								}, 1000)
							}
						}
					})
				} else {
					uni.showModal({
						title: '提示',
						content: err.errMsg,
						showCancel: false,
						success(res) {
							if (res.confirm) {
								setTimeout(() => {
									uni.reLaunch({
										url: '/pages/index/index'
									})
								}, 1000)
							}
						}
					})
				}
				reject(err);
			},
			complete() {
				uni.hideLoading();
				uni.hideToast();
			}
		});
	});
};
// 自定义上传
export const uploadHandle = (data) => {
	const resData = JSON.parse(data.data)
	return resData.data.src
}
export {
	base_url,
	domain_name
};